/**
 * @name 
 * @author skato@salesforce.com
 */
public class SOQLUtils {
    /**
     * @param objectName
     * @return SObject[]
     */
    public static SObject[] selectAllFields(String objectName) {
        System.debug('dadadadadaSelect from ' + objectName);
        return selectAllFields(objectName,'');
    }
    
    /**
     * @param objectName
     * @param condition
     * @return SObject[]
     */
    public static SObject[] selectAllFields(String objectName,String condition) {
        System.debug('Select from ' + objectName + ':condition=' + condition);
        return selectAllFields(objectName,condition,null);
    }
    
    /**
     * @param objectName
     * @return Schema.SObjectType
     */
    public static Schema.SObjectType getSObjectType(String objectName){
        Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
        return gd.get(objectName);
    }
    
    /**
     * @param objectName
     * @param condition
     * @param exceptionFields
     * @return SObject[]
     */
    public static SObject[] selectAllFields(String objectName,String condition,Set<String> exceptionFields) {
        if(objectName == null || objectName.length() == 0){
            //throw System.QueryException;
            System.debug('returning null because invalid argument');
            return null;
        }
        if(exceptionFields == null){
            exceptionFields = new Set<String>{};
        }
        
        System.debug('Getting parameter [' + objectName + '] as a objectName');
        SObject[] result = null;
        String query = '';
        String queryFields = '';
        Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
        System.debug(objectName);
        //Schema.SObjectType sst = gd.get('account');
        Schema.SObjectType sst = Schema.getGlobalDescribe().get(objectName);

        if(sst == null) {
            System.debug('returning null because describe result is null');
            return null;
        }

        for(String field:sst.getDescribe().fields.getMap().keySet()){
            if(!exceptionFields.contains(field)){
                queryFields += field +',';
            }
        }
        query = 'select ' + queryFields.subString(0,queryFields.length()-1) + ' from ' + objectname + condition;
        System.debug('SOQLUtil:query=' + query);
        result = DataBase.query(query);
        System.debug('query result=' + result.size());
        return result;
    }
}